<?php 
if ( ! defined( 'ABSPATH' ) ) exit; ?>
<?php

$plugin_url = plugins_url('',  dirname(__FILE__));

echo "<style>
	#mp.mp-client .client_logout .clogout{
		color: ".get_option('moveto_bg_text_color')." !important;
	}
	#mp .mp-button{
		color : ".get_option('moveto_bg_text_color')." !important;
		background-color: ".get_option('moveto_primary_color')." !important;
	}
	
	#mp .mp-button:hover,
	#mp.mp-client .client_top_bar{
		color: ".get_option('moveto_bg_text_color')." !important;
		background: ".get_option('moveto_secondary_color')." !important;
	}	
	#mp.mp-client #mpclient_list .list_wrapper .list_header{
		color: ".get_option('moveto_bg_text_color')." !important;
		background: ".get_option('moveto_primary_color')." !important;
	}
	#mp .mp-loader .mp-first{
		border: 3px solid ".get_option('moveto_bg_text_color')." !important;
	}
	#mp .mp-loader .mp-second{
		border: 3px solid ".get_option('moveto_primary_color')." !important;
	}
	#mp .mp-loader .mp-third{
		border: 3px solid ".get_option('moveto_secondary_color')." !important;
	}
	


</style>";


if(is_user_logged_in() || (isset($_SESSION['current_user']) && isset($_SESSION['user_id']))){
	global $current_user;
 	$current_user = wp_get_current_user();

	$bookings = new moveto_booking();	
	$bookings->client_id = $current_user->ID;
	$mp_service = new moveto_service();
	$moveto_additional_info = new moveto_additional_info();
	$all_bookings = $bookings->readAll_listing_bookings_front();
	$roomtype_obj=new moveto_room_type();
	$moveto_article_category_obj=new moveto_article_category();

	$moveto_cubic_meter = get_option('moveto_cubic_meter');
	if($moveto_cubic_meter == "ft_3"){
		$moveto_cubic_unit = "Cubic Feet";
	}else{
		$moveto_cubic_unit = "Cubic Meter";
	}
	if(sizeof((array)$all_bookings) > 0) { ?>
		<link rel="stylesheet" href="<?php echo $plugin_url;?>/assets/mp-frontend.css">	
		<link rel="stylesheet" href="<?php echo $plugin_url;?>/assets/mp-responsive.css">	
		<link rel="stylesheet" href="<?php echo $plugin_url;?>/assets/mp-common.css">
		<link rel="stylesheet" href="<?php echo $plugin_url;?>/assets/jquery-ui.min.css">
		<link rel="stylesheet" href="<?php echo $plugin_url;?>/assets/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="<?php echo $plugin_url;?>/assets/line-icons/LineIcons.min.css">
		<div id="mp" class="mp-wrapper mp-client">
			<div class="loader">
				<!-- <div class="loader"><?php //echo __("Loading...","mp");?></div> -->
				<div class="mp-loader">
					<span class="mp-first"></span>
					<span class="mp-second"></span>
					<span class="mp-third"></span>
				</div>
			</div>
			<div class="client_top_bar">
				<div class="mp_clients_header">
					<span class="client_name mp-sm-9 np">Welcome :- <?php echo $current_user->display_name; ?></span>
					<span class="client_logout mp-sm-3  text-right np"><a href="<?php echo wp_logout_url(home_url()); ?>" class="clogout"><i class="icon-power icons icon-space"></i><?php echo __('Logout','mp');?></a></span>
				</div>
			</div>
			<div class="mp_clients_inner">
				<h3 class="mp-xs-12"><?php echo __('Lead Information','mp');?></h3>	
				<form type="" method="POST" action="" id="mpclient_list" >
					<div class="table-responsive">
						<table id="client-dashboard-table" class="table table-striped table-bordered dt-responsive nowrap dataTable no-footer dtr-inline collapsed " cellspacing="0" style="width:100%">
							<thead>
								<tr>
									<th style=""><?php echo __("id","mp");?></th>
									<th style=""><?php echo __("Move Size","mp");?></th>
									<th style=""><?php echo __("Source","mp");?></th>
									<th style=""><?php echo __("Via","mp");?></th>
									<th style=""><?php echo __("Destination","mp");?></th>
									<th style=""><?php echo __("Lead Date","mp");?></th>
									<th style=""><?php echo __("Article Info","mp");?></th>						
									<!-- <th style="width: 65px !important;"><?php echo __("Additional Info","mp");?></th>
									<th style="width: 44px !important;"><?php echo __("Loading Details","mp");?></th>
									<th style="width: 39px !important;"><?php echo __("Unloading Details","mp");?></th>	
									<th style="width: 39px !important;"><?php echo __("Total Cubic Volume","mp");?></th>
									<th style="width: 39px !important;"><?php echo __("Insurance Rate","mp");?></th>	
									
									<th ><?php echo __("Lead Client Info","mp");?></th> -->
									<th><?php echo __("Quote Price","mp");?></th>
									<th ><?php echo __("Payment","mp");?></th>
									<th ><?php echo __("Actions","mp");?></th>
								</tr>
							</thead> 					
							<tbody>
								<?php 
								foreach($all_bookings as $single_booking){ 
									if($single_booking->booking_status=='D'){
										$booking_status = __('Completed','mp');
									}else{
										$booking_status = __('Pending','mp');
									}	
									
									$booking_date = date_i18n('Y-m-d',strtotime($single_booking->booking_date));
									$source_city = $single_booking->source_city;
									$via_city = "";
									if($single_booking->via_city != ""){
										$via_city = $single_booking->via_city;
									}else{
										$via_city = "N/A";
									}
									$destination_city = $single_booking->destination_city;
													
													  
									if($single_booking->booking_status=='D'){
										$bookingstatus = __('Completed','mp');
									}else{
										$bookingstatus = __('Pending','mp');
									}
									/* Get User Info */
									if($single_booking->user_info!=''){
										$userinfo = unserialize($single_booking->user_info);
										if($userinfo != '')
										{
											$pam_email = $userinfo['email'];
											$pam_first_name = ucwords($userinfo['name']);
											$pam_phone = $userinfo['phone'];
										}
									}else{
										$pam_email = '';		$pam_first_name = '';		$pam_phone = '';
										$pam_custom_fields = array();
									}
									/* Get Service Info */

									$service_info = '';
									$home_type_info = '';

									if($single_booking->service_info!=''){
										if($single_booking->move_size){
											$home_type_info = $single_booking->move_size;	
										}else{
											$home_type_info = "N/A";
										}
										

										$service_info_arr = unserialize($single_booking->service_info);
										
										$service_info_cubic_arr = unserialize($single_booking->cubic_feets_article);
										
										//$service_custom_cubic = $service_info_arr['article_cubic'];
											$service_cubic = '';
										if(is_array($service_info_cubic_arr) || is_object($service_info_cubic_arr))
										{
											$service_cubic .= '<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Custom Article :',"mp").'</h5></li>';

											foreach ($service_info_cubic_arr as $value) 
											{
												if(isset($value['cubicfeet_title'])) {
													$service_cubic .= '<li class="common-customer-artical-info"><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Article Name',"mp").'</h5><span class="span-scroll span_indent">'.$value['cubicfeet_title'].'</li>';

													$service_cubic .= '<li class="common-customer-artical-info"><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Quanty',"mp").'</h5><span class="span-scroll span_indent">1</li>';
													
													$service_cubic .= '<li class="common-customer-artical-info"><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Cubic Volume',"mp").'</h5><span class="span-scroll span_indent">'.$value['cubicfeet_count'].'</li>';


												}
											}
										}

										$service_total_cubic_volume = $single_booking->cubic_feets_volume;
										$service_total_cubicvolume = '';
										if($service_total_cubic_volume!='')
										{
											/*$service_total_cubicvolume = '<li><span class="span-scroll span_indent">'.$service_total_cubic_volume.'</li>';*/

											/*$service_total_cubicvolume = '<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Insurance',"mp").'</h5><span class="span-scroll span_indent">'.$service_total_cubic_volume.'</li>';*/
											 
										}

										$service_insurance = $single_booking->insurance_rate;
										$service_total_insurance = '';
										if($service_insurance!='')
										{
											$service_total_insurance = '<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Insurance',"mp").'</h5><span class="span-scroll span_indent">'.$service_insurance.'</li>';
											 
										}
														
										/* $article_name = $service_info_arr['get_article_name']; */

										foreach ($service_info_arr as $key => $value) {
											 
											if(count((array)$value) > 0){
												if(isset($value['get_article_room_id'])) {
													 $room_id=$value['get_article_room_id'];
												}
												if(isset($value['get_article_id'])) {
													$article_id=$value['get_article_id'];
												}	
												if(isset($value['get_article_price'])) {
													$article_price=$value['get_article_price'];
												}	
												
												$moveto_article_category_obj->id=$room_id;
												$room_type_name_array= $moveto_article_category_obj->readOne_room_type();
												
												/* 		$room_type_name= $room_type_name_array[0]->name;
													if(isset($room_type_name)){ */
													/*$service_info .= '<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Room Type',"mp").'</h5><span class="span-scroll span_indent">'.$room_type_name.'</span></li>';*/
												/* 	} */
													//$service_info .= '<li><span class="span-scroll span_indent">'.$value['get_article_name'].'</span><span class="span-scroll span_indent">'.$value['count'].'</span></li>';	
												if(isset($value['get_article_name'])) {
												$service_info .= '<li class="common-customer-artical-info"> <h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Article Name',"mp").'</h5><span class="span-scroll span_indent">'.$value['get_article_name'].'</li>';
												}
												if(isset($value['count'])) {													
												$service_info .= '<li class="common-customer-artical-info"><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Quanty',"mp").'</h5><span class="span-scroll span_indent">'.$value['count'].'</li>';
												}
												if(isset($value['per_quibcfeets_volume'])) { 
												$service_info .= '<li class="common-customer-artical-info"><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Cubic feets Volume',"mp").'</h5><span class="span-scroll span_indent">'.$value['per_quibcfeets_volume'].'</li>';
												}
												/*if(isset($value['tot_article_price'])) {
												$service_info .= '<li style = "list-style: none;margin-left: 10%;"><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Total Price',"mp").'</h5><span class="span-scroll span_indent">'.$value['tot_article_price'].'</li>';
												}*/
												
											}
										}
									}
													
									/* Get Additional Info */
									$additional_info = '';
									if($single_booking->additional_info!=''){
										
										$additional_info_arr = unserialize($single_booking->additional_info);
										$i=1;
										if($additional_info_arr){

												$returndata = $moveto_additional_info->readAll();

												$additionalArr = array();
												foreach ($additional_info_arr['favorite'] as $value) {
												array_push($additionalArr, $value);
												}
													foreach($returndata as $additional){

														if(in_array($additional->id, $additionalArr)){
															$additional_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.$additional->additional_info.'</h5><span class="span-scroll span_indent">Yes</span></li>';
														}else
														{

															$additional_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.$additional->additional_info.'</h5><span class="span-scroll span_indent">No</span></li>';
														}

													}
										}	
											
									}
									/* Get Loading Info */

									$loading_info = '';
									if($single_booking->loading_info!=''){										
										$loading_info_arr = unserialize($single_booking->loading_info);	
											
										$loading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Loading Floor no',"mp").'</h5><span class="span-scroll span_indent">'.$loading_info_arr["loading_floor_number"].'</span></li>';
										$loading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Price Of Loading Floor',"mp").'</h5><span class="span-scroll span_indent">'.$loading_info_arr["loading_floor_amt"].'</span></li>';
										$loading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Load Elevator ?',"mp").'</h5><span class="span-scroll span_indent">'.$loading_info_arr["load_elevator_checked"].'</span></li>';
										$loading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Load Elevator Price',"mp").'</h5><span class="span-scroll span_indent">'.$loading_info_arr["load_elevator_amt"].'</span></li>';
										$loading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Load Packaging  ?',"mp").'</h5><span class="span-scroll span_indent">'.$loading_info_arr["packaging_checked"].'</span></li>';
										$loading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Load Packaging Price ',"mp").'</h5><span class="span-scroll span_indent">'.$loading_info_arr["packaging_amt"].'</span></li>';
										$loading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Street Address',"mp").'</h5><span class="span-scroll span_indent">'.$loading_info_arr["loading_address_one"].'</span></li>';
										$loading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('City',"mp").'</h5><span class="span-scroll span_indent">'.$loading_info_arr["loading_address_two"].'</span></li>';
										$loading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('State',"mp").'</h5><span class="span-scroll span_indent">'.$loading_info_arr["loading_address_three"].'</span></li>';
																			
									}
									/* Get UnLoading Info */
									$unloading_info = '';
									if($single_booking->unloading_info!=''){										
										$unloading_info_arr = unserialize($single_booking->unloading_info);	
																			
										$unloading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Unloading Floor no',"mp").'</h5><span class="span-scroll span_indent">'.$unloading_info_arr["unloading_floor_number"].'</span></li>';
										
										$unloading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Price of Unloading Floor ',"mp").'</h5><span class="span-scroll span_indent">'.$unloading_info_arr["unloading_floor_amt"].'</span></li>';
										
										$unloading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Unload Elevator ?',"mp").'</h5><span class="span-scroll span_indent">'.$unloading_info_arr["unload_elevator_checked"].'</span></li>';
										
										$unloading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Unload Elevator Price',"mp").'</h5><span class="span-scroll span_indent">'.$unloading_info_arr["unload_elevator_amt"].'</span></li>';
										
										$unloading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Unload Unpackaging ?',"mp").'</h5><span class="span-scroll span_indent">'.$unloading_info_arr["unpackaging_checked"].'</span></li>';
										
										$unloading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Unload Unpackaging Price',"mp").'</h5><span class="span-scroll span_indent">'.$unloading_info_arr["unpackaging_amt"].'</span></li>';
										
										$unloading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Street Address',"mp").'</h5><span class="span-scroll span_indent">'.$unloading_info_arr["unloading_address_one"].'</span></li>';
										
										$unloading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('City',"mp").'</h5><span class="span-scroll span_indent">'.$unloading_info_arr["unloading_address_two"].'</span></li>';
										
										$unloading_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('State',"mp").'</h5><span class="span-scroll span_indent">'.$unloading_info_arr["unloading_address_three"].'</span></li>';
										
									}
									
									/* Get Booking Client Info */
													
									$user_info = '';
								
									if($single_booking->user_info!=''){										
										$userinfo = unserialize($single_booking->user_info);
										$pam_email = $userinfo['email'];
										$pam_name = ucfirst($userinfo['name']);
										$pam_phone = $userinfo['phone'];
										
										/* $user_notes	= $user_info_arr["user_notes"];		 */							
										$user_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Name',"mp").'</h5><span class="span-scroll span_indent">'.$pam_name.'</span></li>';
										$user_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Email',"mp").'</h5><span class="span-scroll span_indent">'.$pam_email.'</span></li>';
										$user_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.__('Phone',"mp").'</h5><span class="span-scroll span_indent">'.$pam_phone.'</span></li>';
									
										/* $pam_custom_fields = unserialize($user_info_arr['custom_fields_details']);
										if(sizeof($pam_custom_fields)>0){
											if (is_array($pam_custom_fields) || is_object($pam_custom_fields))
											{
												foreach($pam_custom_fields as $fieldkey => $fieldvalue){
													$user_info .='<li><h5 class="mp-customer-details-hr" style="font-weight: 600;">'.$fieldkey.'</h5><span class="span-scroll span_indent">'.$fieldvalue.'</span></li>';
												}
											}												
										} */
												
									}
									if($single_booking->payment_method != ""){
										$payment = ucwords(str_replace("_", " ", strtolower($single_booking->payment_method)));
									}else{
										$payment = "Unpaid";
									}

									$service_info_all = $service_info."</br>".$service_cubic;
													
									?>
									<tr>
										<td><?php echo $single_booking->order_id; ?></td>
										<td><?php echo $home_type_info;?></td>
										<td><?php echo $source_city; ?></td>
										<td><?php echo $via_city; ?></td>
										<td><?php echo $destination_city; ?></td>
										<td><?php echo date_i18n(get_option('date_format'),strtotime($booking_date)); ?></td>
										<td><?php echo $service_info_all; ?></td>
										<!-- <td><?php echo $additional_info; ?></td>
										<td><?php echo $loading_info; ?></td>
										<td><?php echo $unloading_info; ?></td>
										<td><?php echo $service_total_cubicvolume; ?></td>
										<td><?php echo $service_insurance; ?></td>
										<td><?php echo $user_info; ?></td> -->
										<?php if($single_booking->quote_price!=""){
											?>
											<td><?php echo get_option('moveto_currency_symbol').$single_booking->quote_price; ?></td>
											<?php
										}else{?>
										<td><?php echo "-"; ?></td>
										<?php } ?>
										<td><?php echo $payment; ?></td>
										<td><a href="#pam_send_quotes" data-id="<?php echo $single_booking->id; ?>" role="button" class="btn btn-large btn-primary edit_lead" data-toggle="modal"><?php echo __("Edit","mp");?></a>
										</td>
									</tr>
									<?php 
								} ?>
							</tbody>
						</table>
					</div>
				</form>	
			</div>
		</div>
		<!-- </div> -->
		<div id="pam_send_quotes" class="modal fade">
		    <div class="modal-dialog" style="width: 800px !important;">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                <h4 class="modal-title"><?php echo __("Edit","mp");?></h4>
		            </div>
		           <form id="pam_send_quote_form" class="common-modal-quotes" method="post">
						<div class="modal-body" id="mp">
							<div class="update_appointment_res my_response">
								<div class="row col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<ul class="nav nav-tabs tabs-left sideways">
										<?php     
											$all_records = $roomtype_obj->readAll_room_type_for_front();
											?>
											<input class="" type="hidden" id="last_id_trigger" data-id="<?php echo $all_records[0]->id;?>"> <?php
											$i = 0;
											foreach ($all_records as $room_type )   
											{
												?>
												<li class="room_type_cat" id="<?php if($i==0) echo "first_cat"; ?>" data-id="<?php echo $room_type->id;?>" data-name="<?php echo $room_type->name;?>"><a href="#<?php echo  trim($room_type->name);?>" data-toggle="tab" id="<?php echo  $room_type->id;?>" name="<?php echo $room_type->name;?>"><?php echo  $room_type->name;?></a></li>
										<?php     $i++; 
											} ?>
											<!-- Bhupendra Custom -->
											<li class="room_type_cat cust_quick" id="first_cat" data-id="4" data-name="qucikbid"><a href="#" data-toggle="tab" id="4" name="qucikbid">Custom</a></li>
											<!-- Bhupendra Custom -->
									</ul>
								</div>
								<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
										<div class="articles_tab tab-content">
												
										</div>
								</div>
								 
								<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 multi_quick"  style="display: none;">

								</div>
							</div>
						</div>
						<div class="modal-footer custom-add-btn">
							<button type="button" class="btn btn-default pam_quote_cancel" data-dismiss="modal"><?php echo __("Cancel","mp");?></button>
							<button type="button" id="pam_submit_quote" data-id="<?php echo $single_booking->id; ?>" class="btn btn-primary booking_update"><?php echo __("Edit","mp");?></button>
						</div>
					</form>
		        </div>
		    </div>
		</div>
	<?php 
	}else{

		echo __('No Appointment Found','mp');
	} 
}else{
	?>
	<div id="mp" class="mp-wrapper mp-client mp-client-login">
		<div class="loader">
			<!-- <div class="loader"><?php //echo __("Loading...","mp");?></div> -->
			<div class="mp-loader">
				<span class="mp-first"></span>
				<span class="mp-second"></span>
				<span class="mp-third"></span>
			</div>
		</div>
		<div class="mp_clients_inner">
				<div class="mp_client_login_main mp_client_login_main_wapper">
					<div class="mp_login_inner">
						<h4 class="mp_login_p"><?php echo __('You Must Login to check your Quote Requests','mp'); ?></h4>
						<div class="mp_form_row">
							<label for="mp_client_username_l"><?php echo __('UserName','mp');?></label>
							<input type="text" class="form-control" id="mp_client_username_l" name="mp_client_username" value="" />
							<label id="client_login_username-error"  class="error" ></label>
						</div>
						<div class="mp_form_row">
							<label for="mp_client_password_l"><?php echo __('Password','mp');?></label>
							<input type="password" class="form-control" id="mp_client_password_l" name="mp_client_password" value=""/>
							<label id="client_login_password-error" class="error" ></label>
						</div>
						<div class="mp_form_row">
							<label id="client_login-error" class="error" ></label>
						</div>
						<div class="mp_form_row mp-button_nm_wapper">
							<button class="mp_client_login mp-button nm"><?php echo __('Login','mp');?> </button> <a target="_blank" class="mp_forgot_pass mp-link" href="<?php echo home_url();?>/wp-login.php?action=lostpassword"><?php echo __('Forgot Password?','mp');?></a>
						</div>
					</div>
				</div>
		</div>
	</div>
<?php
} ?>

<script src="<?php echo $plugin_url;?>/assets/js/jquery-2.1.4.min.js"></script>
<script src="<?php echo $plugin_url;?>/assets/js/bootstrap.min.js"></script>
<script src="<?php echo $plugin_url;?>/assets/js/jquery-ui.min.js"></script>
<script src="<?php echo $plugin_url;?>/assets/js/cilent-dashboad.js"></script>
 <script type="text/javascript">
    var objs_booking_list = {"plugin_path":"<?php echo $plugin_url;?>"};
	var appearance_setting = {"default_country_code":"<?php echo get_option('moveto_default_country_short_code'); ?>"};
	var moveto_cubic_unit = "<?php echo get_option('moveto_cubic_meter') ?>";
</script>
<div id="category_manage_modal"> 
</div>